package com.lyf.practice.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/24
 * @VERSION 1.0
 * @DESC
 */
@Configuration
public class RedisTemplateConfig {
    @Bean
    RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<String,Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);

//        redisTemplate.setKeySerializer(new GenericJackson2JsonRedisSerializer());
//
//        // value的序列化
//         redisTemplate.setValueSerializer(new StringRedisSerializer());
//         redisTemplate.setHashValueSerializer(new StringRedisSerializer());
//         redisTemplate.setStringSerializer(new StringRedisSerializer());

        // 2. com.lyf.config all the kind data ,JDK??
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());


        // 3. setting key... to serializer..
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());


        return redisTemplate;
    }
}
